#region NAligner Copyright
/*
 * NAligner
 * C# port of JAligner API, http://jaligner.sourceforge.net
 * 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#endregion
using System;
using System.Text;

namespace NAligner
{
    /// <summary> Holds the output of a pairwise sequences alignment. </summary>
    [Serializable]
    public class PairwiseAlignment
    {
        #region Members

        /// <summary> Gap character</summary>
        public const char GAP = '-';

        /// <summary> Default name for sequence #1</summary>
        private const System.String DEFAULT_SEQUENCE1_NAME = "jaligner_1";

        /// <summary> Default name for sequence #2</summary>
        private const System.String DEFAULT_SEQUENCE2_NAME = "jaligner_2";

        /// <summary> Scoring matrix</summary>
        private string matrix;

        /// <summary> Gap open cost</summary>
        private float open;

        /// <summary> Gap extend cost</summary>
        private float extend;

        /// <summary> Alignment score</summary>
        private float score;

        /// <summary> Aligned sequence #1</summary>
        private char[] sequence1;

        /// <summary> Name of sequence #1</summary>
        private System.String name1;

        /// <summary> Alignment start location in sequence #1</summary>
        private int start1;

        /// <summary> Aligned sequence #2</summary>
        private char[] sequence2;

        /// <summary> Name of sequence #2</summary>
        private System.String name2;

        /// <summary> Alignment start location in sequence #2</summary>
        private int start2;

        /// <summary> Markup line</summary>
        private char[] markupLine;

        /// <summary> Count of identical locations</summary>
        private int identity;

        /// <summary> Count of similar locations</summary>
        private int similarity;

        /// <summary> Count of gap locations</summary>
        private int gaps;

        #endregion

        /// <summary> Constructor for Alignment</summary>
        public PairwiseAlignment()
        {
        }

        /// <returns> Returns the extend. </returns>
        public float Extend
        {
            get
            {
                return extend;
            }
            set
            {
                this.extend = value;
            }
        }

        /// <returns> Returns the matrix. </returns>
        public string Matrix
        {
            get
            {
                return matrix;
            }
            set
            {
                this.matrix = value;
            }
        }

        /// <returns> Returns the name1. </returns>
        public string Name1
        {
            get
            {
                return name1 == null || name1.Length == 0 ? DEFAULT_SEQUENCE1_NAME : name1;
            }
            set
            {
                this.name1 = value;
            }
        }

        /// <returns> Returns the name2. </returns>
        public string Name2
        {
            get
            {
                return name2 == null || name2.Length == 0 ? DEFAULT_SEQUENCE2_NAME : name2;
            }

            set
            {
                this.name2 = value;
            }
        }

        /// <returns> Returns the open. </returns>
        public float Open
        {
            get
            {
                return open;
            }
            set
            {
                this.open = value;
            }
        }

        /// <returns> Returns the score. </returns>
        public float Score
        {
            get
            {
                return score;
            }
            set
            {
                this.score = value;
            }
        }

        /// <returns> Returns the sequence1. </returns>
        public char[] Sequence1
        {
            get
            {
                return sequence1;
            }
            set
            {
                this.sequence1 = value;
            }
        }

        /// <returns> Returns the sequence2. </returns>
        public char[] Sequence2
        {
            get
            {
                return sequence2;
            }
            set
            {
                this.sequence2 = value;
            }
        }

        /// <returns> Returns the start1. </returns>
        public int Start1
        {
            get
            {
                return start1;
            }
            set
            {
                this.start1 = value;
            }
        }

        /// <returns> Returns the start2. </returns>
        public int Start2
        {
            get
            {
                return start2;
            }
            set
            {
                this.start2 = value;
            }
        }

        /// <returns> Returns the gaps. </returns>
        public int Gaps
        {
            get
            {
                return gaps;
            }
            set
            {
                this.gaps = value;
            }
        }

        /// <returns> Returns the identity. </returns>
        public int Identity
        {
            get
            {
                return identity;
            }
            set
            {
                this.identity = value;
            }
        }

        /// <returns> Returns the markupLine. </returns>
        public char[] MarkupLine
        {
            get
            {
                return markupLine;
            }
            set
            {
                this.markupLine = value;
            }
        }

        /// <returns> Returns the similarity. </returns>
        public int Similarity
        {
            get
            {
                return similarity;
            }
            set
            {
                this.similarity = value;
            }
        }

        public float PercentIdentity
        {
            get
            {
                return (Identity / (Sequence1.Length * 1.0f));
            }
        }

        public float PercentSimilarity
        {
            get
            {
                return (Similarity / (Sequence1.Length * 1.0f));
            }
        }
        
        /// <summary> Returns a summary for alignment</summary>
        public string Summary
        {
            get
            {
                StringBuilder buffer = new StringBuilder();
                buffer.Append("Sequence #1: " + Name1);
                buffer.AppendLine();
                buffer.Append("Sequence #2: " + Name2);
                buffer.AppendLine();
                //buffer.Append("Matrix: " + (matrix.Id == null ? "" : matrix.Id));
                //buffer.AppendLine();
                //buffer.Append("Gap open: " + open);
                //buffer.AppendLine();
                //buffer.Append("Gap extend: " + extend);
                //buffer.AppendLine();
                buffer.Append("Identity: " + identity + "/" + Sequence1.Length + " (" + (identity / (Sequence1.Length * 1.0f)).ToString("F2") + ")");
                buffer.AppendLine();
                buffer.Append("Length: " + Sequence1.Length);
                buffer.AppendLine();
                //buffer.Append("Similarity: " + similarity + "/" + Sequence1.Length + " (" + (similarity / (Sequence1.Length * 1.0f)).ToString("F2") + ")");
                //buffer.AppendLine();
                //buffer.Append("Gaps: " + gaps + "/" + Sequence1.Length + " (" + (gaps / (Sequence1.Length * 1.0f)).ToString("F2") + ")");
                //buffer.AppendLine();
                //buffer.Append("Score: " + score.ToString("F2"));
                //buffer.AppendLine();
                return buffer.ToString();
            }
        }
    }
}